<?php

class Bench
{

  protected static $time;

  protected static $last = 0;

  protected static $log = array();

  public static function log($name = '')
  {
    $now = microtime(true);

    if (empty(self::$log)) {
      self::$log[] = array('start', $now, self::$last);
    }
    else {
      self::$log[] = array($name, $now, $now - self::$last);
    }

    self::$last = $now;

    return self::$log;
  }

  public static function time($debug = false)
  {
    $debug = $debug || Simplify::getRequest()->get('get')->has('BENCH_DEBUG');
    return $debug ? self::$log : self::$log[count(self::$log) - 1][1] - self::$log[0][1];
  }

}

?>